home *** CD-ROM | disk | FTP | other *** search
- /*
- dshell v3
-
- 文字列検索
- */
-
-
- #include "dsh.h"
-
-
- static int Inc_search(int *, char *);
- static int Dec_search(int *, char *);
- static int Search_Exec(char *);
- static int underlin(int );
-
-
-
- void
- Menu_find(void)
- {
- struct INPPTR inp;
- int INPLEN = (GMODE) ? 48 : 64;
-
- getstr(&inp, "検索を行なう文字列を入力して下さい(リターンのみで中止)", INPLEN);
-
- /* *****
- ! B_LOCATE( INP_SX,INP_SY+1 );
- ! printf("input string = %s",search_string);
- ***** */
-
- /*
- ! 検索文字が入力されたか?
- */
- if (inp.length == 0) {
- wait_mb_off();
- return;
- }
- /*
- ! 検索実行へ
- */
- Search_Exec(inp.buffer);
-
- /*
- ! 画面の復帰
- */
- msarea(0, 0, GWIDTH - 1, 511);
- p_scr();
- wait_mb_off();
- }
-
- /*
- サーチ選択メニュー用構造体
- (なんかあまりウツクシクない…)
- */
- struct ITEM {
- int posx; /* 表示開始x位置(offset:chr) init_...デ初期化スルノ */
- int meslen; /* 項目文字列長さ(chr) init_...デ初期化スルノ */
- char *mes; /* メニュー項目 */
- };
-
- struct MENU {
- int sx; /* メニュー表示開始x座標(chr) */
- int sy; /* メニュー表示開始y座標(chr) */
- int lx; /* メニューx長さ(chr) */
- int ly; /* メニューy長さ(chr) */
- int in; /* 項目数 */
- struct ITEM *items; /* 項目実体 */
- };
-
- /*
- 検索実行
- */
- static int
- Search_Exec(char *string)
- {
- int i;
- int dmx, dmy, mx, my, mbl, mbr;
- int tx, otx;
- int curlin; /* 検索現在(検索開始)行(0<=curlin<lpmx) */
- int flin; /* 表示上の現在行(0<=flin<30):下線引いて目立たせるため */
-
- static void init_SrchMenu(struct MENU *);
- static void display_menu(struct MENU *);
- static void display_item(struct MENU *, int, int);
- static int check_select_menu(int, struct MENU *);
-
-
- struct ITEM SMItem[]=
- {
- {0, 0, "前方検索"},
- {0, 0, "後方検索"},
- {0, 0, "[終了]"}
- };
-
- #define ITEMN ( sizeof( SMItem ) / sizeof( struct ITEM ) ) /* 項目数:3 */
- #define WIN_SY 29 /* 同上?? */
- struct MENU SrchMenu =
- {
- 0, /* メニュー表示開始x座標(dummy) */
- WIN_SY, /* メニュー表示開始y座標 */
- 0, /* メニューx長さ(init_...デ初期化スルノ) */
- 1, /* メニューy長さ(横長メニューナノネ) */
- ITEMN, /* アイテム数 */
- SMItem /* 項目実体 */
- };
-
- SrchMenu.sx = CWIDTH - 34;
-
-
-
- init_SrchMenu(&SrchMenu);
-
- display_menu(&SrchMenu);
-
- /*
- ! セレクト(検索開始)
- */
- otx = -1;
- curlin = lp; /* 検索文字列更新の都度、 curlin も更新される */
- while (1) {
- dmsstat(&dmx, &dmy, &mbl, &mbr);
- dmspos(&mx, &my);
- p_time(0);
- /*
- ! 右ボタン(キャンセル)
- */
- if (mbr) {
- break;
- }
- /*
- ! 左ボタン(決定)
- */
- if (otx != -1 && mbl) {
- switch (tx) {
- case 0:
- flin = Inc_search(&curlin, string);
- break;
- case 1:
- flin = Dec_search(&curlin, string);
- break;
- case 2:
- return (0);
- default:
- break;
- }
- p_scr();
- p_fpt(1);
- if (flin >= 0) {
- underlin(flin);
- }
- display_menu(&SrchMenu);
- otx = -1;
- wait_mb_off();
- }
- /*
- ! メニュー選択チェック
- */
- i = check_select_menu(mx, &SrchMenu);
- if (i >= 0 && i != otx) {
- tx = i;
- display_item(&SrchMenu, otx, 3); /* 白色 */
- display_item(&SrchMenu, tx, 13); /* 水色反転 */
- otx = tx;
- }
- /* otx=tx; */
- }
-
- return (1);
- }
-
- /*
- 前方検索
- clin 更新:
- 見つかった場合、
- lp も更新、表示上の該当行を返す
- 見つからなかった場合は-1を返す
- */
- static int
- Inc_search(int *clin, char *string)
- {
- if (++(*clin) >= lpmx) {
- --(*clin);
- }
- for (; *clin < lpmx; ++(*clin)) {
- if (dinstr(lhp[*clin], string) != 0) {
- lp = *clin - 15;
- if (lp + 30 >= lpmx) {
- lp = lpmx - 30;
- }
- if (lp < 0) {
- lp = 0;
- }
- return (*clin - lp);
- }
- }
- return (-1);
- }
-
- /*
- 後方検索
- clin 更新:
- 見つかった場合、
- lp も更新、表示上の該当行を返す
- 見つからなかった場合は-1を返す
- */
- static int
- Dec_search(int *clin, char *string)
- {
- if (--(*clin) < 0) {
- ++(*clin);
- }
- for (; *clin >= 0; --(*clin)) {
- if (dinstr(lhp[*clin], string) != 0) {
- lp = *clin - 15;
- if (lp + 30 >= lpmx) {
- lp = lpmx - 30;
- }
- if (lp < 0) {
- lp = 0;
- }
- return (*clin - lp);
- }
- }
- return (-1);
- }
-
- /*
- マウスカーソルのエリアなど初期化
- */
- static void
- init_SrchMenu(struct MENU *menu)
- {
- int i, l;
-
- /* posxとmeslenとmenu->lxを計算 */
-
- l = 2;
- for (i = 0; i < menu->in; i++) {
- menu->items[i].posx = l;
- menu->items[i].meslen = strlen(menu->items[i].mes);
- l += menu->items[i].meslen;
- l += 2;
- }
- menu->lx = l;
- /*
- マウスカーソルエリア固定
- */
- msarea(menu->sx * 8, menu->sy * 16, (menu->sx + menu->lx) * 8, (menu->sy + menu->ly) * 16);
- }
-
- /*
- ! 選択メニュー表示
- */
- static void
- display_item(struct MENU *menu, int no, int color)
- {
- if (no >= 0 && no < menu->in) {
- B_LOCATE(menu->sx + menu->items[no].posx, menu->sy);
- B_COLOR(color);
- B_PRINT(menu->items[no].mes);
- B_COLOR(3); /* normal color */
- }
- }
-
- static void
- display_menu(struct MENU *menu)
- {
- int i;
-
- tbox_w2(menu->sx, menu->sy, menu->sx + menu->lx, menu->sy + menu->ly);
- for (i = 0; i < menu->in; i++) {
- display_item(menu, i, 3);
- }
- }
-
-
- /*
- メニュー選択判定(カーソル当たり判定?)
-
- mx:マウスカーソルのx位置(dot)
- */
- static int
- check_select_menu(int mx, struct MENU *menu)
- {
- int i, tmpx;
-
- mx /= 8;
- for (i = 0; i < menu->in; i++) {
- tmpx = menu->sx + menu->items[i].posx;
- if (mx >= tmpx && mx <= (tmpx + menu->items[i].meslen)) {
- return (i);
- }
- }
- return (-1);
- }
-
- /*
- アンダーラインを引く
- 汎用性のカケラもない関数じゃ…
- */
- static int
- underlin(int lin)
- {
- struct XLINEPTR txxptr;
-
- txxptr.vram_page = 1; /* vram_page */
- txxptr.x = 0; /* x */
- txxptr.y = 0; /* y */
- txxptr.x1 = 768; /* x1 */
- txxptr.line_style = 0xffff; /* line_style */
-
- if (lin < 0) {
- return (-1); /* 用心… */
- }
-
- txxptr.y = (lin + 2) * 16;
- TXXLINE(&txxptr);
-
- return (0);
- }
-
- /* [ EOF ] */
-